﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using FA_Model;
using FA_Server;

namespace FixedAssets.Controls
{
    public partial class Create_MDC_Control : System.Web.UI.UserControl
    {
        FA_S_MasterDataCard s_mdc;
        protected void Page_Load(object sender, EventArgs e)
        {
            s_mdc = new FA_S_MasterDataCard("JW00000001");
            DataBding();
        }

        private void DataBding()
        {
            this.P_C_MDC.Controls.Add(CreateControl(s_mdc.lMDCS[1].D_Code_Name));
        }


        private Control CreateControl(Dictionary<string, string> dcn)
        {
            Control control = new Control();
            int i = 1;
            //WebControl webcontrol=new WebControl(HtmlTextWriterTag.Style);
            //webcontrol.Style=HtmlTextWriterStyle.BorderColor;
            Table table = new Table();
            table.Style.Add(HtmlTextWriterStyle.TextAlign, "Left");
            table.Style.Add(HtmlTextWriterStyle.Margin, "0");
            WebControl br_wc = new WebControl(HtmlTextWriterTag.Br);
            TableRow tr = new TableRow();

            foreach (KeyValuePair<string, string> kv in dcn)
            {
                TableCell tc = new TableCell();
                tc.BorderWidth = 2;
                tc.BorderColor = System.Drawing.Color.CadetBlue;
                Label ln = new Label();
                ln.Text = "&nbsp;" + kv.Value + " :&nbsp;";
                ln.Style.Add(HtmlTextWriterStyle.MarginLeft, "10");
                ln.Style.Add(HtmlTextWriterStyle.BorderWidth, "2");
                TextBox tb_v = new TextBox();
                tc.Controls.Add(ln);
                tc.Controls.Add(tb_v);
                if (i % 4 == 0)
                {

                    tr.Controls.Add(tc);
                    table.Controls.Add(tr);
                    tr = new TableRow();
                    tr.BorderWidth = 2;
                    tr.BorderColor = System.Drawing.Color.CadetBlue;
                }
                else
                {
                    tr.Controls.Add(tc);
                }
                i++;
            }
            if (i % 4 != 0)
                table.Controls.Add(tr);

            control.Controls.Add(table);
            return control;
        }
    }


     
}